/**
 * Copyright &copy; 2012-2016 <a href="https://istep.lczyfz.com">Istep</a> All rights reserved.
 */
package com.lczyfz.istep.modules.teach.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.lczyfz.istep.common.config.Global;
import com.lczyfz.istep.common.persistence.Page;
import com.lczyfz.istep.common.web.BaseController;
import com.lczyfz.istep.common.utils.StringUtils;
import com.lczyfz.istep.modules.teach.entity.TeachPapercount;
import com.lczyfz.istep.modules.teach.service.TeachPapercountService;

/**
 * 试卷计数表Controller
 * @author cqh
 * @version 2017-06-08
 */
@Controller
@RequestMapping(value = "${adminPath}/teach/teachPapercount")
public class TeachPapercountController extends BaseController {

	@Autowired
	private TeachPapercountService teachPapercountService;
	
	@ModelAttribute
	public TeachPapercount get(@RequestParam(required=false) String id) {
		TeachPapercount entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = teachPapercountService.get(id);
		}
		if (entity == null){
			entity = new TeachPapercount();
		}
		return entity;
	}
	
	@RequiresPermissions("teach:teachPapercount:view")
	@RequestMapping(value = {"list", ""})
	public String list(TeachPapercount teachPapercount, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TeachPapercount> page = teachPapercountService.findPage(new Page<TeachPapercount>(request, response), teachPapercount); 
		model.addAttribute("page", page);
		return "modules/teach/teachPapercountList";
	}

	@RequiresPermissions("teach:teachPapercount:view")
	@RequestMapping(value = "form")
	public String form(TeachPapercount teachPapercount, Model model) {
		model.addAttribute("teachPapercount", teachPapercount);
		return "modules/teach/teachPapercountForm";
	}

	@RequiresPermissions("teach:teachPapercount:edit")
	@RequestMapping(value = "save")
	public String save(TeachPapercount teachPapercount, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, teachPapercount)){
			return form(teachPapercount, model);
		}
		teachPapercountService.save(teachPapercount);
		addMessage(redirectAttributes, "保存试卷计数表成功");
		return "redirect:"+Global.getAdminPath()+"/teach/teachPapercount/?repage";
	}
	
	@RequiresPermissions("teach:teachPapercount:edit")
	@RequestMapping(value = "delete")
	public String delete(TeachPapercount teachPapercount, RedirectAttributes redirectAttributes) {
		teachPapercountService.delete(teachPapercount);
		addMessage(redirectAttributes, "删除试卷计数表成功");
		return "redirect:"+Global.getAdminPath()+"/teach/teachPapercount/?repage";
	}

}